// components/upload/upload.js
const app = getApp()
import { uploadImage } from '../../utils/uploadImage'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    url: { type: String },
  },

  lifetimes: {
    attached() {
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    avatarID: null,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    change() {
      this.triggerEvent('change', 'child')
    },
    doUpload: function () {
      // 选择图片
      const filename = 'avatar' + Date.now()
      uploadImage(this, filename).then(res => {
        this.setData({ avatarID: res.fileID, })
        app.globalData.avatarID = res.fileID
        this.triggerEvent('change', res.fileID)
      })
    },
    previewImg() {
      const {
        avatarID
      } = this.data
      console.log(avatarID)
      wx.previewImage({
        current: avatarID, // 当前显示图片的http链接
        urls: [avatarID] // 需要预览的图片http链接列表
      })
    },
  }
})
